package com.atguigu.controller.front;

import com.atguigu.client.UcenterClient;
import com.atguigu.domain.EduComment;
import com.atguigu.service.EduCommentService;
import com.atguigu.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/eduservice/comment")
@CrossOrigin
public class CommentController {
    @Autowired
    private UcenterClient ucenterClient;

    @Autowired
    private EduCommentService eduCommentService;

    @PostMapping("addComment")
    public R addComment(@RequestBody EduComment eduComment){
        eduCommentService.save(eduComment);
        return R.ok();
    }

    @PostMapping("getPageList/{page}/{limit}/{courseId}")
    public R getPageList(@PathVariable long page,
                         @PathVariable long limit,
                         @PathVariable String courseId){
        Page<EduComment> commentPage = new Page<>(page,limit);

        Map<String,Object> map = eduCommentService.getPageList(commentPage,courseId);
        return R.ok().data(map);
    }
}
